﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NerdOnRails.DynamicProxy.Tests.Mocks;

namespace NerdOnRails.DynamicProxy.Tests
{
	 [TestClass]
	 public class ProxyTests
	 {
		  [TestMethod]
		  public void TestThatYouCanInterceptBeforeAMethodIsCalled()
		  {
				String actual = String.Empty;
				String expected = "this is a test";

				dynamic obj = Proxy.CreateProxy<MockedObject>((methodName, type, args) => { actual = args.First().ToString(); }, (methodName, type, result) => { });
				obj.SetContent(expected);
				Assert.IsTrue(actual == expected);
		  }

		  [TestMethod]
		  public void TestThatYouCanInterceptAfterAMethodIsCalled()
		  {
				String actual = String.Empty;
				String expected = "this is a test";

				dynamic obj = Proxy.CreateProxy<MockedObject>((methodName, type, args) => { }, (methodName, type, result) => { actual = result.ToString(); });
				obj.SetContent(expected);

				Assert.IsTrue(actual == expected);
		  }

		  [TestMethod]
		  public void TestThatPropertiesBehaveLikeNormal()
		  {
				dynamic obj = Proxy.CreateProxy<MockedObject>((methodName, type, args) => { }, (methodName, type, result) => { });
				obj.Content = "more Tests";
				Assert.IsTrue(obj.Content == "more Tests");
		  }
	 }
}
